package com.song.javathread_day01.ch1_8;

import java.util.Date;
import java.util.Deque;
import java.util.concurrent.TimeUnit;

import org.apache.log4j.Logger;

public class WriterTask implements Runnable {

	private Deque<Event> deque;
	
	
	
	public WriterTask(Deque<Event> deque) {
		super();
		this.deque = deque;
	}



	public void run() {
		
		ch1_8.logger.debug("writer task thread-"+Thread.currentThread().getId()+" is start!");
		for(int i =1 ;i<100 ;i++)
		{
			Event event = new Event();
			event.setDate(new Date());
			event.setEvent(String.format("The thread %s has generated an  event", Thread.currentThread().getId()));
			ch1_8.logger.debug("The writertask  thread-"+ Thread.currentThread().getId()+" has generated an  event");
			deque.addFirst(event);
			
			try {
				TimeUnit.SECONDS.sleep(1);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
		}
		
	}

}
